import axios from 'axios';
let ROOT_URL;
switch (process.env.nodejs_env) {
    case 'dev':
        ROOT_URL = '/'
        break;
    default:
        ROOT_URL = 'http://127.0.0.1:8888'
        break;
}
// axios.defaults.baseURL = ROOT_URL;
const request = axios.create({
    baseURL:ROOT_URL,
    xsrfCookieName: 'csrftoken',
    xsrfHeaderName: 'X-CSRFToken',
    timeOut: 10000
})
const api = {
    get:(url='/',params={})=>{
        try {
            return new Promise((resolve,reject)=>{
                request.get(url,{params})
                .then(res=>{
                    resolve(res.data)
                })
                .catch((err) => {
                    reject(err);
                });
            })
            
        } catch (error) {
            
        }
    },
    post:(url='/',params={})=>{
        try {
            return new Promise((resolve,reject)=>{
                request.post(url,params)
                .then(res=>{
                    console.log(res)
                    resolve(res.data)
                })
                .catch((err) => {
                    reject(err);
                });
            })
            
        } catch (error) {
            
        }
    }
}
export default api;
